<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        div {
            margin: 10px;
            width: 50px;
            height: 50px;
            float: left;
            border: 1px solid #c5ffbb;
        }
        .highlight {
            background-color: red;
        }
        .timesToggle {
            background: #9e73ff;
        }
        .bold {
            font-weight: bolder;
        }
        .complex {
            border: 2px dotted #00B7FF;
            border-radius: 5% 10% 15% 20%;
            background-color: #fff2b7;
        }
    </style>
</head>
<body>
<nav>
    <button>高亮切换</button>
    <button>每点击三次切换</button>
    <button>字体变粗</button>
    <button>参数为函数</button>
    <button></button>
</nav>


<div class="highlight"></div>
<div class="timesToggle"></div>
<div class="bold">粗体</div>
<div class="complex"></div>
<div class=""></div>
<script src="jquery-1.12.4.js" type="text/javascript"></script>
<script>
    $(function () {
        $("button:eq(0)").bind("click", function () {
            $("div:eq(0)").toggleClass("highlight");
        });
        var times = 0, times2 = 0;
        $("button:eq(1)").on("click", function () {
            times++;
            // toggleClass(className, switch)
            // switch为bool值，为真则添加class，每点击三次则添加timeToggle
            $("div:eq(1)").toggleClass("timesToggle", times % 3 === 0);
            console.log(times, times % 3 === 0);
        });
        $("button:eq(2)").on("click", function () {
            // 值为true，有/无class切换，值为false，去除class
            $("div:eq(2)").toggleClass(true);
        });
        $("button:eq(3)").bind("click", function () {
            times2++;
            $("div:eq(3)").toggleClass(function () {
                return "complex";
            }, times2 % 5 ===0);
            // 每5次变换
            console.log(times2, times2 % 5 ===0);
        });
    })
</script>
</body>
</html>